package view;

import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;

import model.WestPanelEnum;
import controller.ACSystem;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.border.LineBorder;

import java.awt.Color;

/**
 * The logIn pane 
 * @author Bob Landowski
 *
 */
@SuppressWarnings("serial")
public class LogInPane extends JPanel {
	
	/** The user name */
	private JTextField username_textField;
	
	/** The Accontroller */
	private ACSystem my_ACcontroller;
	
	/** The password field */
	private JPasswordField password_textField;
	
	/**
	 * Create the panel.
	 * @author Bob Landowski
	 * @author Eric Struck
	 * 
	 */
	public LogInPane(final ACSystem the_ACcontroller) {
		setBorder(new LineBorder(new Color(0, 0, 0), 5));
		my_ACcontroller = the_ACcontroller;
		setLayout(null);
		setPreferredSize(new Dimension(400,400));
		JLabel welcome_lable = new JLabel("Auction Central Log In");
		welcome_lable.setBounds(142, 16, 178, 20);
		add(welcome_lable);

		JLabel username_label = new JLabel("User Name:");
		username_label.setBounds(36, 76, 103, 20);
		add(username_label);

		username_textField = new JTextField();
		username_textField.setBounds(142, 73, 146, 26);
		add(username_textField);		
		username_textField.setColumns(10);

		JLabel password_label = new JLabel("Password:");
		password_label.setBounds(36, 123, 88, 20);
		add(password_label);

		password_textField = new JPasswordField();
		password_textField.setBounds(141, 120, 147, 26);
		add(password_textField);

		JButton submit_button = new JButton("Submit");
		submit_button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				saveData();
				my_ACcontroller.checkCredentials();
			}
		});
		submit_button.setBounds(151, 174, 115, 29);
		add(submit_button);

		JButton register_button = new JButton("Register");
		register_button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				my_ACcontroller.setWestPanel(WestPanelEnum.NEWUSER);
				my_ACcontroller.getMainFrame().westPanelState(new Object());
			}
		});
		register_button.setBounds(151, 235, 115, 29);
		add(register_button);

	}

	/**
	 * Sends username and password to the controller.
	 */
	@SuppressWarnings("deprecation")
	public void saveData(){
		my_ACcontroller.setMy_userName(username_textField.getText());
		my_ACcontroller.setMy_password(password_textField.getText());
	}

	/** The get=GUI method */
	public Component getGUI() {
		// TODO Auto-generated method stub
		return null;
	}
}
